#include "Netcal.hpp"
#include "Protocol.hpp"
#include "TcpServer.hpp"
#include<iostream>
#include <memory>

void Usage(std::string proc)
{
    std::cerr << "Usage: " << proc << " port" << std::endl;
}

int main(int argc,char* argv[]){
    if(argc != 2){
        Usage(argv[0]);
        exit(USAGE_ERR);
    }
    //应用层
    std::unique_ptr<Cal> cal = std::make_unique<Cal>();

    //协议层会话层
    //序列化和反序列化
    std::unique_ptr<Protocol> a = std::make_unique<Protocol>([&cal](Request& req)->Response{
        return cal->Execute(req);
    });
    //接收业务逻辑存入


    //服务端会话层
    //创建文件描述符创建Tcp套接字
    std::unique_ptr<TcpServer> tsvr = std::make_unique<TcpServer>(std::stoi(argv[1]),[&a](std::shared_ptr<Socket> &_sock, InetAddr &client){
        a->GetRequest(_sock,client);
    });

    tsvr->Start();
}